const defaultState = {
    loading: false,
    dataSource: [],
    clientList: [],
    carrierList: [],
    currencyList: [],
    businessCodeList: [],
    selectedRowKeys: [],
    feeList: [],
    rateList: [],
    page: 1,
    pageSize: 20,
    totalElements: 0,
    filter: {}
};
export default function list(state = defaultState, action) {
    const {type, payload, error} = action;
    switch (type) {

        case 'ZAD_ORDER_RECEIVABLE.QUERY':
            if (error === true) {
                return {...state, loading: false};
            }
            return {
                ...state,
                loading: false,
                dataSource: payload.content,
                page: payload.page,
                pageSize: payload.pageSize,
                totalElements: payload.totalElements,
                selectedRowKeys: []
            };
        case 'ZAD_ORDER_RECEIVABLE.GET_CLIENT':
            return {...state, clientList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.QUERY_PENDING':
            return {...state, filter: {...payload}};
        case 'ZAD_ORDER_RECEIVABLE.GET_CARRIER':
            return {...state, carrierList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.GET_CURRENCY':
            return {...state, currencyList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.LOCK':
            return {...state, selectedRowKeys: []};
        case 'ZAD_ORDER_RECEIVABLE.UN_LOCK':
            return {...state, selectedRowKeys: []};
        case 'ZAD_ORDER_RECEIVABLE.GET_BUSINESS_CODE_LIST':
            return {...state, businessCodeList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.UPDATE_DATA_SOURCE':
            return {...state, dataSource: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.GET_FEE_LIST':
            return {...state, feeList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.GET_RATE':
            return {...state, rateList: [...payload]};
        case 'ZAD_ORDER_RECEIVABLE.SELECT':
            return {...state, selectedRowKeys: payload};
        case 'ZAD_ORDER_RECEIVABLE.RE_CALCULATE_FEE_PENDING':
            return {...state, loading: true};
        case 'ZAD_ORDER_RECEIVABLE.RE_CALCULATE_FEE':
            return {...state, loading: false};
        default:
            return state;
    }
}

